package edu.task.repository;

import edu.task.model.SysUser;
import edu.task.repository.custom.SysUserCustomRepository;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SysUserRepository extends JpaRepository<SysUser, Long>, SysUserCustomRepository {

    @Modifying
    @Query(value = "update sys_user set del_flag='2' where user_id in :userIds",nativeQuery = true)
    int deleteUserByIds(Long[] userIds);

    @Modifying
    @Query(value = " delete ur from sys_user_role as ur " +
            "inner join sys_user as u on ur.user_id = u.user_id " +
            "inner join sys_role as r on ur.role_id = r.role_id " +
            "where ur.user_id=:userId ", nativeQuery = true)
    int deleteUserRoleByUserId(Long userId);

    @Modifying
    @Query(value = "select * from sys_user where user_name=:name", nativeQuery = true)
    List<SysUser> selectUserByName(String name);
}
